cm.figs <-function(dat=cm1,pwidth=7,pheight=10){
  pdffile <- paste("cm_plots_",format(Sys.time(),'%d-%b-%Y_%H.%M' ),".pdf",sep="")
    pdf(file=pdffile,width=pwidth,height=pheight)
  par(mfcol=c(2,1))
  # plot observed and predicted average weights
  plot(dat$yrs_pf,dat$obs_aw,xlab="Years",ylab="Average weight",main="Pot fishery",pch=19)
  lines(dat$yrs_pf,dat$pred_aw,lwd=3,col="red")
  
  # plot observed and predicted trawl survey abundances
  plot(dat$yrs_ts,dat$x_ts,xlab="Years",ylab="Survey abundance",ylim=c(0,max(dat$x_ts)*1.05),main="Trawl survey",pch=19)
  lines(dat$yrs_ts,dat$X_ts,lwd=3,col="red")
  
  # plot observed and predicted Pot survey abundances
  plot(dat$yrs_ps,dat$x_ps,ylim=c(0,1.2*max(dat$X_ps)*1.06),xlab="Years",ylab="Survey abundance",main="Pot survey",pch=19,cex=2)
  lines(dat$yrs_ps,dat$X_ps,lwd=3,col="red")  
  
  # plot time series of Fs
  plot(1978:(length(dat$F)+1977),dat$F,pch=19,cex=1.5,xlab="Year",ylab="F",main="Fishing mortality")
  lines(1978:(length(dat$F)+1977),dat$F,lwd=3,col="red")
  
  #plot(dat$mm,dat$sel_ts,pch=19,cex=1,xlab="Carapace Width (mm)",ylab="F",main="Trawl survey",typ="b",xlim=c(0,120))
  #abline(v=112) 
  #abline(v=97)
  #plot(dat$mm,dat$sel_ps,pch=19,cex=1,xlab="Carapace Width (mm)",ylab="F",main="Pot survey",typ="b")
  #abline(v=112) 
  #abline(v=97)
   #plot(dat$mm,dat$sel_pf,pch=19,cex=1,xlab="Carapace Width (mm)",ylab="F",main="Pot fishery",typ="b")
  #abline(v=112) 
  #abline(v=97)
  
  
  # Get sdreport variables of interest and there std errors...
  rec=cmfit$est[cmfit$names=="New"]
  rec.std=cmfit$std[cmfit$names=="New"]
  
  Ntot=cmfit$est[cmfit$names=="Ntot"]
  Ntot.std=cmfit$std[cmfit$names=="Ntot"]
  
  # plot CI for recs and Ntot
  plotCI(1978:2011,rec,2*rec.std,ylim=c(0,max(rec+2*rec.std)),ylab="Recruitment", xlab="Year")
  points(1978:2011,rec,pch=19,cex=1.2)
  
  #Overlay last year's "recruits"
  points(1978:2010,R2010,pch=12,col="red",cex=2)
  
  plotCI(1978:2011,Ntot,2*Ntot.std,ylim=c(0,max(Ntot+4*Ntot.std)),ylab="Abundance", xlab="Year")
  points(1978:2011,Ntot,pch=19,cex=1.2)
  
  #Overlay last year's "totals"
  points(1978:2010,N2010,pch=12,col="red",cex=2)
  
  par(mfcol=c(1,1))
  StageFits(dat=dat)
  dev.off()
}
